package com.lry.basic.lambda;

import java.util.function.*;

public class Demo1 {
    //Consumer Supplier Predicate Function
    public static void main(String[] args) {
        //Consumer
        Consumer consumer = x ->{
            System.out.println("consumer:"+x);
        };
        consumer.accept(1);

        BiConsumer<String,String> biConsumer = (x,y)->{
            System.out.println("biConsumer:"+x+" "+y);
        };
        biConsumer.accept("a","b");

        //Supplier
        Supplier<Integer> supplier = ()->1;
        System.out.println(supplier.get());

        //Predicate
        Predicate<Integer> predicate = x->{
            if((x&1)==0){
                return false;
            }
            return true;
        };
        System.out.println(predicate.test(1));

        BiPredicate<Integer,Integer> biPredicate = (x,y)->{
            if(x>y)
                return true;
            return false;
        };
        System.out.println(biPredicate.test(1, 2));


        //Function
        Function<String,String> function = x->  "hello "+x;

        System.out.println(function.apply("lry"));

        BiFunction<String,Integer,String> biFunction = (x,y)-> "hello "+x+" age="+y;
        System.out.println(biFunction.apply("lry",24));
    }

}
